<?php

class Webmix_AdminGlobalController extends Core_Controller_Action_Admin
{
  public function indexAction()
  {
    $this->view->navigation = $navigation = Engine_Api::_()->getApi('menus', 'core')
      ->getNavigation('webmix_admin_main', array(), 'webmix_admin_main_global');

    
    $this->view->form = $form = new Webmix_Form_Admin_Settings_Global();
   
    // Check post
    if( !$this->getRequest()->isPost() ) {
       $code = Engine_Api::_()->getApi('settings','core')->getSetting('webmix.adsense.code','');
       $form->code->setValue($code);
       $form->background->setValue(Engine_Api::_()->getApi('settings','core')->getSetting('webmix.block.background','white'));
       $form->emptybackgound->setValue(Engine_Api::_()->getApi('settings','core')->getSetting('webmix.block.emptybackgound','white'));
       $form->webmix_backgound->setValue(Engine_Api::_()->getApi('settings','core')->getSetting('webmix.webmix.background','#FFFFFF'));
       $form->block_color->setValue(Engine_Api::_()->getApi('settings','core')->getSetting('webmix.block.color','#CCCCCC'));
       
       $form->create_color->setValue(Engine_Api::_()->getApi('settings','core')->getSetting('webmix.createcolor.color','#153665'));
       $form->countries_color->setValue(Engine_Api::_()->getApi('settings','core')->getSetting('webmix.countriescolor.color','#5F93B4'));
       $form->tab_color->setValue(Engine_Api::_()->getApi('settings','core')->getSetting('webmix.tabcolor.color','#EAEAEA'));
       
       $form->tab_backgroudcolor->setValue(Engine_Api::_()->getApi('settings','core')->getSetting('webmix.tab.backgroudcolor','#0E95C9'));
       $form->activetab_backgroudcolor->setValue(Engine_Api::_()->getApi('settings','core')->getSetting('webmix.activetab.backgroudcolor','#E4E4E4'));
       
       $form->admintab_color->setValue(Engine_Api::_()->getApi('settings','core')->getSetting('webmix.admintab.color','#8F8F8F'));
       $form->icon_country->setValue(Engine_Api::_()->getApi('settings','core')->getSetting('webmix.icon.country','http://demo.idragonsolution.com/webmix/application/modules/Core/externals/images/report.png'));
       $form->icon_homepage->setValue(Engine_Api::_()->getApi('settings','core')->getSetting('webmix.icon.homepage','http://demo.idragonsolution.com/webmix/application/modules/Core/externals/images/star_big.png'));
       $b = Engine_Api::_()->getApi('settings','core')->getSetting('webmix.webmix.background','#FFFFFF');
       $this->view->b = $b;
       
       $c = Engine_Api::_()->getApi('settings','core')->getSetting('webmix.block.color','#CCCCCC');
       $this->view->c = $c;
       
       $create = Engine_Api::_()->getApi('settings','core')->getSetting('webmix.createcolor.color','#153665');
       $this->view->create = $create;
        
       $country = Engine_Api::_()->getApi('settings','core')->getSetting('webmix.countriescolor.color','#5F93B4');
       $this->view->country = $country;
        
       $tab = Engine_Api::_()->getApi('settings','core')->getSetting('webmix.tabcolor.color','#EAEAEA');
       $this->view->tab = $tab;
       
       $tab_background = Engine_Api::_()->getApi('settings','core')->getSetting('webmix.tab.backgroudcolor','#0E95C9');
       $this->view->tab_backgroudcolor = $tab_background;
       
       $activetab_backgroudcolor = Engine_Api::_()->getApi('settings','core')->getSetting('webmix.activetab.backgroudcolor','#E4E4E4');
       $this->view->activetab_backgroudcolor = $activetab_backgroudcolor;
       
       $admintab_color = Engine_Api::_()->getApi('settings','core')->getSetting('webmix.admintab.color','#8F8F8F');
       $this->view->admintab_color = $admintab_color;
       
       $this->view->backgound = $backgound;
       $this->view->color = $color;
      return;
    }

    // Check validitiy
    if( !$form->isValid($this->getRequest()->getPost()) ) {
      return;
    }
   
    Engine_Api::_()->getApi('settings','core')->setSetting('webmix.adsense.code',$form->code->getValue());
    Engine_Api::_()->getApi('settings','core')->setSetting('webmix.block.background',$form->background->getValue());
    Engine_Api::_()->getApi('settings','core')->setSetting('webmix.webmix.background',$form->webmix_backgound->getValue());
    Engine_Api::_()->getApi('settings','core')->setSetting('webmix.block.color',$form->block_color->getValue());
    Engine_Api::_()->getApi('settings','core')->setSetting('webmix.block.emptybackgound',$form->emptybackgound->getValue());
    
    Engine_Api::_()->getApi('settings','core')->setSetting('webmix.createcolor.color',$form->create_color->getValue());
    Engine_Api::_()->getApi('settings','core')->setSetting('webmix.countriescolor.color',$form->countries_color->getValue());
    Engine_Api::_()->getApi('settings','core')->setSetting('webmix.tabcolor.color',$form->tab_color->getValue());
    
    Engine_Api::_()->getApi('settings','core')->setSetting('webmix.tab.backgroudcolor',$form->tab_backgroudcolor->getValue());
    Engine_Api::_()->getApi('settings','core')->setSetting('webmix.activetab.backgroudcolor',$form->activetab_backgroudcolor->getValue());
    
    Engine_Api::_()->getApi('settings','core')->setSetting('webmix.admintab.color',$form->admintab_color->getValue());
    Engine_Api::_()->getApi('settings','core')->setSetting('webmix.icon.country',$form->icon_country->getValue());
    Engine_Api::_()->getApi('settings','core')->setSetting('webmix.icon.homepage',$form->icon_homepage->getValue());
    
    $b = Engine_Api::_()->getApi('settings','core')->getSetting('webmix.webmix.background','#FFFFFF');
    $this->view->b = $b;
    
    $c = Engine_Api::_()->getApi('settings','core')->getSetting('webmix.block.color','#CCCCCC');
    $this->view->c = $c;
    
    $create = Engine_Api::_()->getApi('settings','core')->getSetting('webmix.createcolor.color','#153665');
    $this->view->create = $create;
    
    $country = Engine_Api::_()->getApi('settings','core')->getSetting('webmix.countriescolor.color','#5F93B4');
    $this->view->country = $country;
    
    $tab = Engine_Api::_()->getApi('settings','core')->getSetting('webmix.tabcolor.color','#EAEAEA');
    $this->view->tab = $tab;
    
     $tab_background = Engine_Api::_()->getApi('settings','core')->getSetting('webmix.tab.backgroudcolor','#0E95C9');
     $this->view->tab_backgroudcolor = $tab_background;
       
     $activetab_backgroudcolor = Engine_Api::_()->getApi('settings','core')->getSetting('webmix.activetab.backgroudcolor','#E4E4E4');
     $this->view->activetab_backgroudcolor = $activetab_backgroudcolor;
     
     $admintab_color = Engine_Api::_()->getApi('settings','core')->getSetting('webmix.admintab.color','#8F8F8F');
     $this->view->admintab_color = $admintab_color;
       
    $form->addNotice('Your changes have been saved.');
  }

}